package modele;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Collection;
import java.util.TreeSet;

public class PaysDAO {

    public static Collection<Dep> getLesDeps() {
        Collection<Dep> lesDeps = new TreeSet<Dep>();

        Connection con;
        Statement req;
        con = Connect.get();

        try {

            req = con.createStatement();

            ResultSet rs = req.executeQuery("select distinct departement from medecin");
            while (rs.next()) {
                Dep d = new Dep(rs.getString("departement"));
                lesDeps.add(d);
            }

        } catch (SQLException e) {
            System.out.println("Erreur SQL :" + e);
        }

        return lesDeps;
    }

    public static Collection<Spe> getLesSpes() {
        Collection<Spe> lesSpes = new TreeSet<Spe>();

        Connection con;
        Statement req;
        con = Connect.get();

        try {

            req = con.createStatement();

            ResultSet rs = req.executeQuery("select distinct specialitecomplementaire from medecin");
            while (rs.next()) {
                if(rs.getString("specialitecomplementaire")!=null) {
                    Spe s = new Spe(rs.getString("specialitecomplementaire"));
                    lesSpes.add(s);
                }
            }

        } catch (SQLException e) {
            System.out.println("Erreur SQL :" + e);
        }

        return lesSpes;
    }
    
    public static Collection<Med> getLesMeds() {
        Collection<Med> lesMeds = new TreeSet<Med>();
        
        Connection con;
        Statement req;
        con = Connect.get();
        
        try {
            
            req = con.createStatement();
        
            ResultSet rs = req.executeQuery("select id,nom,prenom,adresse,tel,specialitecomplementaire, departement from medecin");
            while (rs.next()) {
                Med m = new Med(rs.getString("nom"), rs.getString("prenom"),
                        rs.getString("adresse"), rs.getString("tel"), rs.getString("specialitecomplementaire"), 
                        rs.getString("id"), rs.getString("departement"));
                lesMeds.add(m);
            }

        } catch (SQLException e) {
            System.out.println("Erreur SQL :" + e);
        }

        return lesMeds;
    }
}